package com.jic.finance.impl;

import java.lang.Long;
import java.util.List;

import com.jic.common.base.vo.Page;
import com.jic.common.base.vo.PageResult;
import com.jic.finance.entity.CurrencyManage;
import com.jic.finance.mapper.CurrencyManageMapper;
import com.jic.finance.request.manager.CurrencyManageRequest;
import com.jic.finance.service.CurrencyManageService;

import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 币种管理
 * @author : 
 * @email : 
 * @since : 2020-02-29 07:09:46
 * @version : v1.0.0
 */
@Service
public class CurrencyManageServiceImpl implements CurrencyManageService{

    @Autowired
    private CurrencyManageMapper currencyManageMapper;

    @Override
    public long insert(CurrencyManageRequest currencyManageRequest) {
        CurrencyManage manage = new CurrencyManage();
        BeanUtils.copyProperties(currencyManageRequest,manage);
        long flag = currencyManageMapper.insert(manage);
        return flag;
    }

    @Override
    public long delete(Long id) {
        return currencyManageMapper.delete(id);
    }

    @Override
    public long update(CurrencyManageRequest currencyManageRequest) {
        return currencyManageMapper.update(currencyManageRequest);
    }

    @Override
    public CurrencyManage queryByPrimaryKey(Long id){
        return currencyManageMapper.queryByPrimaryKey(id);
    }

    @Override
    public List<CurrencyManage> query(CurrencyManage currencyManage){
        return currencyManageMapper.query(currencyManage);
    }

    @Override
    public PageResult<CurrencyManage> queryPage(CurrencyManageRequest currencyManageRequest, Page pageQuery) {
        //计算下标
        int startIndex = (pageQuery.getStart() - 1) * pageQuery.getLimit();
        List<CurrencyManage> list = currencyManageMapper.queryPage(startIndex, pageQuery.getLimit(), currencyManageRequest);
        long count = currencyManageMapper.queryPageCount(currencyManageRequest);
        PageResult pageResult = new PageResult();
        pageResult.setRows(list);
        pageResult.setTotal(count);
        return pageResult;
    }
}